Fix nightly and improve merge error message
authorAlex Crichton <alex@alexcrichton.com>
Mon, 19 Jan 2015 05:02:25 +0000 (21:02 -0800)
committerAlex Crichton <alex@alexcrichton.com>
Mon, 19 Jan 2015 05:02:25 +0000 (21:02 -0800)
The nightly bots are all failing because a nightly build emits a .cargo/config
which uses `[target]` for some overrides, but a test was creating invalid
configuration for `[target]`, causing the test error message to change.

This commit fixes the test by using a different error message (which should not
conflict). It also improves the error message for "configuration could not be
merged" to include more contextual information about what just happened.

src/cargo/util/config.rs
tests/test_bad_config.rs

index 46bb6915d289d521020d10a22420cda1e9a05cfe..ae36e427de3bb99f68c90e78f8ab8de9ae93ef33 100644 (file)
@@ -273,8 +273,21 @@ impl ConfigValue {
             (&mut CV::Table(ref mut old, _), CV::Table(ref mut new, _)) => {
                 let new = mem::replace(new, HashMap::new());
                 for (key, value) in new.into_iter() {
-                    match old.entry(key) {
-                        Occupied(mut entry) => { try!(entry.get_mut().merge(value)); }
+                    match old.entry(key.clone()) {
+                        Occupied(mut entry) => {
+                            let path = value.definition_path().clone();
+                            let entry = entry.get_mut();
+                            try!(entry.merge(value).chain_error(|| {
+                                human(format!("failed to merge key `{}` between \
+                                               files:\n  \
+                                               file 1: {}\n  \
+                                               file 2: {}",
+                                              key,
+                                              entry.definition_path().display(),
+                                              path.display()))
+
+                            }));
+                        }
                         Vacant(entry) => { entry.insert(value); }
                     };
                 }
index 3b23fd3fff4c3945c53b51d78ea9d75ea285d7de..4597ae763f1511568de8cb8f0ff5ec9e85f8be1c 100644 (file)
@@ -1,4 +1,4 @@
-use support::{project, execs};
+use support::{project, execs, cargo_dir};
 use hamcrest::assert_that;
 
 fn setup() {}
@@ -13,11 +13,13 @@ test!(bad1 {
         "#)
         .file("src/lib.rs", "")
         .file(".cargo/config", r#"
-              target = "foo"
+              [target]
+              nonexistent-target = "foo"
         "#);
-    assert_that(foo.cargo_process("build").arg("-v"),
+    assert_that(foo.cargo_process("build").arg("-v")
+                   .arg("--target=nonexistent-target"),
                 execs().with_status(101).with_stderr("\
-expected table for configuration key `target`, but found string in [..]config
+expected table for configuration key `target.nonexistent-target`, but found string in [..]config
 "));
 });
 
@@ -88,6 +90,32 @@ expected a string, but found a boolean in [..]config
 "));
 });
 
+test!(bad5 {
+    let foo = project("foo")
+        .file(".cargo/config", r#"
+            foo = ""
+        "#)
+        .file("foo/.cargo/config", r#"
+            foo = 2
+        "#);
+    foo.build();
+    assert_that(foo.process(cargo_dir().join("cargo")).arg("new")
+                   .arg("-v").arg("foo").cwd(foo.root().join("foo")),
+                execs().with_status(101).with_stderr("\
+Failed to create project `foo` at `[..]`
+
+Caused by:
+  Couldn't load Cargo configuration
+
+Caused by:
+  failed to merge key `foo` between files:
+  file 1: [..]foo[..]foo[..]config
+  file 2: [..]foo[..]config
+
+Caused by:
+  expected integer, but found string
+"));
+});
 
 test!(bad_cargo_config_jobs {
     let foo = project("foo")